import { defineStore } from 'pinia';

type Message = {
  id: string;
  role: 'user' | 'assistant';
  content: string;
  timestamp: Date;
  status?: 'sending' | 'sent' | 'failed';
};

export const useChatStore = defineStore('chat', {
  state: () => ({
    messages: [] as Message[]
  }),
  actions: {
    addMessage(message: Message) {
      this.messages.push(message);
    },
    updateMessageStatus(id: string, status: 'sending' | 'sent' | 'failed') {
      const message = this.messages.find(m => m.id === id);
      if (message) {
        message.status = status;
      }
    },
    clearMessages() {
      this.messages = [];
    }
  }
});